package com.itheima.login;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.Scanner;

public class Login {
    public static void main(String[] args) throws IOException {
        //需求
        //获取用户输入账户和密码
        //判断是否正确
        //正确提示登录成功
        //不正确提示登录失败

        //1.读取userinfo.txt中的用户信息
        BufferedReader br = new BufferedReader(new FileReader("E:\\Java\\day19\\userinfo.txt"));
        String line = br.readLine();

        //获取用户名和密码
        String[] arrInfo = line.split("&");
        String rightUsername = arrInfo[0].split("=")[1];
        String rightPassword = arrInfo[1].split("=")[1];
        System.out.println(rightUsername);
        System.out.println(rightPassword);

        //2.获取用户录入的用户信息
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入用户名:");
        String username = scanner.nextLine();
        System.out.println("请输入密码:");
        String password = scanner.nextLine();

        //3.比较是否正确
        if (rightUsername.equals(username) && rightPassword.equals(password)){
            System.out.println("登录成功");
        }else {
            System.out.println("登录失败,用户名或密码错误");
        }

    }
}
